<?php
namespace Index\Base;
use Think\Controller;
Vendor('Wechat.wechat','','.class.php');
import("@.ORG.Util.Input");//用于安全过滤

/**
 * 前台公共类
 */
class BaseController extends Controller {

    public function _initialize() {

	    $this->assign('key2', KEY);
        $this->assign('key3', DESC);
        $this->assign('key4', SITE2);
        $this->assign('ad', AD);
        $foo2 = split(',', FOO2);
        $this->assign('ff', $foo2);

        if(method_exists($this,'_infoModule')){
            $this->assign('infoModule',$this->_infoModule());
        }
    }

    /**
     * 前台模板显示 调用内置的模板引擎显示方法，
     * @access protected
     * @param string $templateFile 指定要调用的模板文件
     * @return void
     */
    protected function common_display($templateFile='') {
        $common = $this->fetch('Public/common/common.html');
        $tpl = $this->fetch($templateFile);
        echo str_replace('<!--common-->', $tpl, $common);
    }

    /**
     * 获取分页数量
     * @param int $count 数据总数
     * @param int $listRows 每页数量
     */
    protected function getPageLimit($count,$listRows) {
        $this->assign('rowcount',($_GET['p']?$_GET['p'] - 1:0) * $listRows);
        $this->pager = new \Think\Page($count,$listRows);
        $this->pager -> setConfig('header','共%TOTAL_ROW%条');
        $this->pager -> setConfig('first','首页');
        $this->pager -> setConfig('last','共%TOTAL_PAGE%页');
        $this->pager -> setConfig('prev','上一页');
        $this->pager -> setConfig('next','下一页');
        $this->pager -> setConfig('link','indexpagenumb');//pagenumb 会替换成页码
        $this-> pager -> setConfig('theme','%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
        return $this->pager->firstRow.','.$this->pager->listRows;
    }

    /**
     * 分页显示
     * @param array $map 分页附加参数
     */
    protected function getPageShow($map = '') {
        if(!empty($map)){
            $map = array_filter($map);
            $this->pager->parameter = $map;
        }
        return $this->pager->show();
    }
    

    
    protected function get_url() {
        return 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    }

  
}